#include <stdio.h>
#include <string.h>

typedef struct 
{
    int id;
    char name[20];
    int age;
}student;


int main()
{
    //文件指针
    FILE *f = fopen("test.txt","w");

    if(f == NULL)
    {
        printf("文件打开失败!\n");
        return -1;
    }

    printf("文件打开成功!\n");

    // const char *str = "你好,这是我第一次写文件";
    // while(*str != '\0')
    // {
    //     fputc(*str,f);
    //     str++;
    // }
    // printf("\n");

    // const char *s = "这是对fputs写入文件字符串的测试\n";
    // fputs(s,f);


    // const char *s = "这是对fwrite写入文件字符串的测试\n";
    // printf("%d\n",fwrite(s,1024,1,f));

    student stu;
    stu.id = 1;
    strcpy(stu.name,"zhangsan");
    stu.age = 20;

    //把一个结构体放入文件
    fprintf(f,"%d %s %d",stu.id,stu.name,stu.age);

    fclose(f);
    return 0;
}